﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace Kira.Compiler.Bods
{
    [XmlElementMapping("DITable")]
    public class DITable : BodsObject
    {

        public String Owner
        {
            get { return this.GetAttrbuteValue("owner"); }
        }
        public String Datastore
        {
            get { return this.GetAttrbuteValue("datastore"); }
        }
        public String Database
        {
            get { return this.GetAttrbuteValue("database"); }
        }

        public IEnumerable<DIColumn> Columns
        {
            get
            {
                return this.GetElements<DIColumn>();
            }
        }
    }

    [XmlElementMapping]
    public class DIColumn : BodsElementBase
    {

        public String Name
        {
            get { return this.GetAttrbuteValue("name"); }
        }

        public BodsDataType DataType
        {
            get
            {
                return (BodsDataType)Enum.Parse(typeof(BodsDataType), this.GetAttrbuteValue("datatype"), true);
            }
        }

        public bool Nullable
        {
            get
            {
                return this.HasAttribute("nullable") ? bool.Parse(this.GetAttrbuteValue("nullable")) : false;
            }
        }

        public bool HasSize
        {
            get
            {
                return this.HasAttribute("size");
            }
        }

        public int Size
        {
            get { return this.GetAttrbuteIntegerValue("size"); }
        }

        public bool HasPrecision
        {
            get
            {
                return this.HasAttribute("precision");
            }

        }

        public int Precision
        {
            get { return this.GetAttrbuteIntegerValue("precision"); }
        }

        public bool HasScale
        {
            get { return this.HasAttribute("scale"); }
        }

        public int Scale
        {
            get
            {
                return this.GetAttrbuteIntegerValue("scale");
            }
        }
    }
}
